package com.water_work_form.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.water_work_form.entity.RecordSynchronousComparison;
import com.water_work_form.entity.RecordTitration;
import com.water_work_form.result.Result;
import com.water_work_form.result.ResultCodeEnum;
import com.water_work_form.result.ResultUtil;
import com.water_work_form.service.RecordSynchronousComparisonService;
import com.water_work_form.service.RecordTitrationService;
import com.water_work_form.util.RandomIdUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 记录——滴定质控 前端控制器
 * </p>
 *
 * @author xuke
 * @since 2023-10-16
 */
@RestController
@RequestMapping("/record-titration")
public class RecordTitrationController {

    @Autowired
    RecordTitrationService recordTitrationService;

    /**
     * 记录——津滨水厂同步比对原始记录 项目新增
     * @param recordTitration 新数据
     * @return 返回相应code表示状态 0为成功
     */
    @ApiOperation("新增")
    @PostMapping("/add")
    public Result addRecordTitration(@RequestBody RecordTitration recordTitration){
        recordTitration.setId(RandomIdUtil.createRandomId());
        recordTitrationService.save(recordTitration);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, recordTitration);
    }

    /**
     *
     * @param type
     * @param checkStartDate
     * @param checkEndDate
     * @param checkSite
     * @param status
     * @param current
     * @param size
     * @return
     */
    @ApiOperation("查看(分页)")
    @GetMapping("/pageList")
    public Result listRecordTitration(@RequestParam("type") String type, @RequestParam("checkStartDate") String checkStartDate, @RequestParam("checkEndDate") String checkEndDate,
                                      @RequestParam("checkSite") String checkSite, @RequestParam("status") String status, @RequestParam("current") Integer current,
                                      @RequestParam("size") Integer size){
        IPage<RecordTitration> page = recordTitrationService.selectRecordTitration(type, checkStartDate, checkEndDate, checkSite, status, current, size);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, page);
    }

    /**
     * 记录——津滨水厂同步比对原始记录 项目删除
     * @param id 需要删除的数据id
     * @return 返回code表示状态 0为成功
     */
    @ApiOperation("删除")
    @DeleteMapping("/delete")
    public Result deleteRecordTitration(@RequestParam("id") Long id){
        recordTitrationService.removeById(id);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     * 记录——津滨水厂同步比对原始记录 项目更新
     * @param recordTitration 修改后的数据
     * @return 返回code表示状态 0为成功
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public Result updateRecordTitration(@RequestBody RecordTitration recordTitration){
        recordTitrationService.updateById(recordTitration);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

    /**
     *
     * @param formName
     * @param sampleName
     * @param phBlindName
     * @param phProject
     * @param waterId
     * @param drugName
     * @param restrictionName
     * @param formulaName
     * @return
     */
    @ApiOperation("基础表数据查询")
    @GetMapping("/basicList")
    public Result listBasicTitration( @RequestParam("formName") String formName, @RequestParam("sampleName") String sampleName, @RequestParam("phBlindName") String phBlindName, @RequestParam("phProject") String phProject,
                                      @RequestParam("waterId") String waterId, @RequestParam("drugName") String drugName, @RequestParam("restrictionName") String restrictionName, @RequestParam("formulaName") String formulaName){
        Map<String,Object> map = recordTitrationService.selectBasicTitration(formName, sampleName, phBlindName, phProject, waterId, drugName, restrictionName, formulaName);
        return ResultUtil.success(ResultCodeEnum.SUCCESS, map);
    }

    /**
     * 记录——津滨水厂同步比对原始记录 数据表导出
     * @param recordTitration 需要导出的数据列表
     * @return 返回相应数据
     * @throws IOException 异常
     */
    @ApiOperation("列表导出")
    @PostMapping(value = "/download-word")
    public Result downloadWordRecordTitration(@RequestBody RecordTitration recordTitration) throws IOException  {
        recordTitrationService.downloadRecordTitration(recordTitration);
        return ResultUtil.success(ResultCodeEnum.SUCCESS);
    }

}

